package com.rogo.log
{
	import avmplus.getQualifiedClassName;
	
	import mx.logging.ILogger;
	import mx.logging.ILoggingTarget;
	import mx.logging.Log;
	
	/**
	 * 程序日志类
	 * 
	 * @author Rogo
	 */	
	public class AppLog
	{
		public function AppLog()
		{
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constants
		//
		//--------------------------------------------------------------------------
		
		/**
		 * 日志等级 致命日志
		 */	
		public static const FATAL:int = 1000;
		
		/**
		 * 日志等级 错误日志
		 */	
		public static const ERROR:int = 8;
		
		/**
		 * 日志等级 警告日志
		 */	
		public static const WARN:int = 6;
		
		/**
		 * 日志等级 信息日志
		 */	
		public static const INFO:int = 4;
		
		/**
		 * 日志等级 调试日志
		 */	
		public static const DEBUG:int = 2;
		
		/**
		 * 日志等级 所有日志 
		 */		
		public static const ALL:int = 0;
		
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		
		private static var logTarget:ILoggingTarget;
		
		private static var _level:int = AppLog.ERROR;
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		/**
		 * 获取记录器
		 * 
		 * @return 
		 */		
		public static function getLogger(instance:*):ILogger
		{
			if (!logTarget)
			{
				logTarget = new AppLogTarget();
				logTarget.level = _level;
				Log.addTarget(logTarget);
			}
			
			var category:String = getQualifiedClassName(instance).replace('::', '.');
			return Log.getLogger(category);
		}
		
		/**
		 * 记录器级别 默认级别ERROR
		 * 
		 * @param value
		 */		
		public static function set level(value:int):void
		{
			_level = value;
			
			if (logTarget)
				logTarget.level = _level;
		}
		
		
	}
}